using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DynamicMuzzle:Upgrade {

	const float threshold = 5;
	protected override void BurstDecidingEventHandler(object _sender,BurstDecidingEventArgs e) {
		base.BurstDecidingEventHandler(_sender,e);
		float targetDistance = (weapon.owner.targetPosition-weapon.owner.position).magnitude;
		float amount = targetDistance-threshold;
		amount=Mathf.Clamp(amount,-4,4);
		e.stat.cooldownTime.AddDivideAdd(-amount*0.08f,0);
	}
	protected override void ShootingEventHandler(object _sender,ShootEventArgs e) {
		base.ShootingEventHandler(_sender,e);
		float targetDistance = (weapon.owner.targetPosition-weapon.owner.position).magnitude;
		float amount = targetDistance-threshold;
		amount=Mathf.Clamp(amount,-4,4);
		e.stat.cooldownTime.AddDivideAdd(-amount*0.08f,0);
	}

	protected override void ProjectileFiringEventHandler(object _sender,ProjectileEventArgs e) {
		base.ProjectileFiringEventHandler(_sender,e);
		float targetDistance = (weapon.owner.targetPosition-weapon.owner.position).magnitude;
		float amount = targetDistance-threshold;
		amount=Mathf.Clamp(amount,-4,4);
		e.stat.inaccuracy.AddDivideAdd(amount*0.15f,0);
		e.stat.speed.AddMultAdd(amount*0.15f,0);
	}

	public override void Update(object sender,WeaponEventArgs e) {
		base.Update(sender,e);
		float targetDistance = (weapon.owner.targetPosition-weapon.owner.position).magnitude;
		float amount = targetDistance-threshold;
		amount=(Mathf.Clamp(amount,-4,4)+4)/8f;
		AddProgression(amount);
	}

}
